package com.wutuo.institution.provider.service;

import cn.apestar.core.framework.exception.BusinessException;
import cn.apestar.user.provider.institution.cache.InstitutionCacheProvider;
import cn.apestar.user.provider.institution.request.InstitutionRequest;
import cn.apestar.user.provider.institution.response.InstitutionResponse;
import cn.apestar.user.provider.institution.service.InstitutionService;
import com.wutuo.institution.api.InstitutionWTAPIService;
import com.wutuo.institution.api.response.InstitutionAllResponse;
import com.wutuo.institution.provider.component.InstitutionDataConvert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Singer_YDW on 2016/11/9.
 */
@Service("institutionWTService") public class InstitutionWTService
    implements InstitutionWTAPIService {
    @Autowired private InstitutionCacheProvider institutionCacheProvider;

    @Autowired private InstitutionService institutionService;
    public void initCache() {

        List<InstitutionResponse> list = list(new InstitutionRequest(), false);
        for (int i = 0; i < list.size(); i++) {
            InstitutionResponse s = list.get(i);
            institutionCacheProvider.deleteCache(s.getId());
        }
    }

    @Override
    public InstitutionAllResponse getInstitutionByAllDetailId(Long id, Long userId) {

        InstitutionResponse institution = getById(id);
        if (institution == null)
            throw new BusinessException("institution.is.not.exists");
        return InstitutionDataConvert.convertToInstitutionResponse(institution, userId);
    }

    @Override public void addorUpdate(InstitutionRequest record) {
        institutionService.addorUpdate(record);
    }

    @Override public void addUserAndInstition(Long institutionId, Long userId) {
        institutionService.addUserAndInstition(institutionId, userId);
    }

    @Override public InstitutionResponse getById(Long id) {
        return institutionService.getById(id);
    }

    @Override public void del(Long id) {
        institutionService.del(id);
    }

    @Override public List<InstitutionResponse> list(InstitutionRequest request, boolean flag) {
        return institutionService.list(request, flag);
    }

    @Override public <T> void getCminstanById(List list, String tKey, String skey, boolean flag) {

    }

    @Override public void clearCache(Long id) {

    }

    @Override public List<InstitutionResponse> listInstitutionForIds(String ids) {
        return null;
    }
}
